#include "string_util.h"

#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <gtest/gtest.h>
#include <string>
#include <vector>

TEST(StringUtil, HexStrToCharactor)
{
    std::string content = "hello-world..;../.../...,,,";
    std::string hex;
    StringUtil::DataToHexStr(content.c_str(), content.size(), hex);
    printf("raw content : %s.\n", content.c_str());
    printf("hex data : %s.\n", hex.c_str());
    std::vector<uint8_t> charactor_vec;
    StringUtil::HexStrToCharacter(hex, charactor_vec);
    for (std::size_t index = 0; index < charactor_vec.size(); index++)
    {
        printf("%c", charactor_vec[index]);
    }
    printf(".\n");
}

TEST(StringUtil, BeToHN)
{
    uint16_t  data = 0;
    uint8_t * ptr  = (uint8_t *)&data;
    *(ptr)         = 0x01;
    *(ptr + 1)     = 0x00;
    // 0x0001
    printf("raw data : %d.\n", data);
    // 0x0100
    uint16_t dst = 0;
    StringUtil::BeToHN((uint8_t *)&dst, ptr, sizeof(dst));
    printf("dst data : %d.\n", dst);
}

TEST(StringUtil, HtoBeN)
{
    uint16_t  data = 0;
    uint8_t * ptr  = (uint8_t *)&data;
    *(ptr)         = 0x01;
    *(ptr + 1)     = 0x00;
    // 0x0001
    printf("raw data : %d.\n", data);
    // 0x0100
	printf("net data : %d and target data : %d.\n", StringUtil::HtoBe16(data), 0x0100);

}
